const Router = require('koa-router')
const path = require('path')
const swaggerJSDoc = require('swagger-jsdoc')
const router = new Router({
    prefix: '/swagger' // 路由前缀
})
const swaggerDefinition = {
    info: {
        title: 'API 接口',
        version: 'v1'
    }
}
const options = {
    swaggerDefinition,
    apis: [path.join(__dirname, './docs/*.js')] // 写有注解的router的存放地址, 最好     path.join()
}
const swaggerSpec = swaggerJSDoc(options)
// 通过路由获取生成的注解文件
router.get('/swagger.json', async function (ctx) {
    ctx.set('Content-Type', 'application/json')
    ctx.body = swaggerSpec
})
module.exports = router
